package com.zky.controller;

import com.zky.domain.ResponseResult;
import com.zky.domain.dto.AddArticleDto;
import com.zky.domain.dto.UpdataArticleDto;
import com.zky.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult addArticle(@RequestBody AddArticleDto article){
        return articleService.addArticle(article);
    }

    @GetMapping("/list")
    public ResponseResult getAllArticleList(Integer pageNum, Integer pageSize, String title, String summary){
        return articleService.getAllArticleList(pageNum, pageSize, title, summary);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleById(@PathVariable Long id){
        return articleService.getArticleById(id);
    }

    @PutMapping
    public ResponseResult updateArticle(@RequestBody UpdataArticleDto updataArticleDto){
        return articleService.updateArticle(updataArticleDto);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable Long id){
        return articleService.deleteArticle(id);
    }
}